<?php
class Collect_OpModel extends Collect_BaseModel {
	protected $rules;public function reorder($zym_18, $rules, $zym_17 = true) {
		static $logmodel, $zym_16, $zym_19;if (!$logmodel) {
			$logmodel = new NovelSearch_LogModel();
			$zym_16 = new NovelSearch_chapterModel();
			$zym_19 = new compare();}$zym_20 = $this->model->get('novelsearch_info', $zym_18);
		$zym_24 = $zym_20['novel']['name'];
		$zym_22 = $logmodel->where(['novelid' => $zym_18])->getfield('siteid', true);foreach ($rules as $zym_23) {
			$zym_15 = $this->getrule($zym_23, $zym_17);if (in_array($zym_15['siteid'], $zym_22)) {
				$this->progress("《{$zym_24}》使用基准规则 {$zym_15['name']}");
				$zym_16->setTableId($zym_18);
				$zym_21 = $zym_16->field('id')->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->select();
				$zym_25 = 0;foreach ($zym_21 as $zym_12) {
					$zym_25++;
					$zym_16->where(['id' => $zym_12['id']])->update(['oid' => $zym_25]);}if ($zym_15['siteid'] == $zym_20['source']['siteid']) {(new NovelSearch_infoModel())->where(['id' => $zym_18])->update(['orderid' => $zym_25]);}$logmodel->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->update(['oid' => $zym_25]);
				$this->progress("《{$zym_24}》使用基准规则 重排完毕,开始处理其他站点");
				$zym_21 = $zym_16->field('id,oid,name')->where(array('novelid' => $zym_18, 'siteid' => $zym_15['siteid']))->order('id asc')->select();foreach ($zym_22 as $zym_7) {
					if ($zym_7 == $zym_15['siteid']) {
						continue;
					}

					$zym_6 = $zym_16->field('id,oid,name')->where(array('novelid' => $zym_18, 'siteid' => $zym_7))->order('id asc')->select();foreach ($zym_6 as $zym_5 => $zym_12) {$zym_6[$zym_5]['oid'] = 0;}$zym_6 = $zym_19->run($zym_6, $zym_21, $zym_20);
					$zym_8 = 0;foreach ($zym_6 as $zym_12) {
						if ($zym_8 < $zym_12['oid']) {
							$zym_8 = $zym_12['oid'];
						}

						$zym_16->where(['id' => $zym_12['id']])->update(['oid' => $zym_12['oid']]);}$logmodel->where(['novelid' => $zym_18, 'siteid' => $zym_7])->update(['oid' => $zym_8]);if ($zym_15['siteid'] == $zym_20['source']['siteid']) {(new NovelSearch_infoModel())->where(['id' => $zym_18])->update(['orderid' => $zym_8]);}$this->progress("《{$zym_24}》站点({$zym_7})处理完毕");}$this->progress("《{$zym_24}》所有站点处理完毕");return;}}$this->progress("<{$zym_18}>没有发现与之匹配的基准规则,跳过", 'warning');}public function recollect($zym_18, $zym_23, $zym_14) {
		static $logmodel, $zym_16, $zym_13, $zym_15;if (!$logmodel) {
			$logmodel = new NovelSearch_LogModel();
			$zym_16 = new NovelSearch_chapterModel();
			$zym_13 = new CollectModel($zym_23);
			$zym_15 = $this->getrule($zym_23);}$zym_9 = $logmodel->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->find();if ($zym_9) {
			$zym_16->setTableId($zym_18);if ($zym_14) {$zym_16->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid'], 'time' => ['between', $zym_14]])->delete();} else { $zym_16->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->delete();}$logmodel->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->update(['lastid' => 0]);
			$this->progress("<{$zym_18}>清除数据成功,重新采集");
			$zym_13->collectidone($zym_9['fromid'], false);} else { $this->progress("<{$zym_18}>没有使用{$zym_15['name']}采集过,跳过", 'warning');}}public function updateinfo($zym_18, $zym_23) {
		static $logmodel, $zym_13, $zym_15, $zym_11;if (!$logmodel) {
			$logmodel = new NovelSearch_LogModel();
			$zym_13 = new CollectModel($zym_23);
			$zym_15 = $this->getrule($zym_23);
			$zym_11 = new NovelSearch_infoModel();}$zym_9 = $logmodel->where(['novelid' => $zym_18, 'siteid' => $zym_15['siteid']])->find();if ($zym_9) {
			$zym_10 = $zym_15['url_info'];
			$zym_10['rule'] = str_replace(['[novelid]', '[subnovelid]'], [$zym_9['fromid'], subid($zym_9['fromid'])], $zym_10['rule']);
			$zym_26 = $zym_13->getinfo($zym_10);if ($zym_26['status'] == 0) {$this->progress("<{$zym_18}>获取信息失败", 'warning');}$zym_6 = ['id' => $zym_18];if (isset($_POST['updateintro'])) {$zym_6['intro'] = $zym_26['data']['intro'];}if (isset($_POST['updatecover'])) {$zym_6['cover'] = $zym_26['data']['cover'];}if (isset($_POST['updatecategory'])) {$zym_6['categoryid'] = $zym_26['data']['categoryid'];}if (isset($_POST['updateisover']) && isset($zym_26['data']['isover'])) {$zym_6['isover'] = $zym_26['data']['isover'];}if ($zym_6) {
				$zym_11->where(['id' => $zym_18])->edit($zym_6);
				$this->progress("<{$zym_18}>更新成功");} else { $this->progress("<{$zym_18}>没有要更新的内容");}} else { $this->progress("<{$zym_18}>没有使用{$zym_15['name']}采集过,跳过", 'warning');}}public function getrule($zym_23, $zym_17 = true) {static $ruleModel;if (!$ruleModel) {$ruleModel = new ruleModel();}if (isset($this->rules[$zym_23])) {return $this->rules[$zym_23];} else {return $this->rules[$zym_23] = $zym_17 ? $ruleModel->getrule($zym_23) : $ruleModel->getrulebysiteid($zym_23);}}}
?>